﻿// -------------------------------------------------------------------------
//    @FileName         :    NFPacketSendUtil.h
//    @Author           :    gaoyi
//    @Date             :    24-8-8
//    @Email            :    445267987@qq.com
//    @Module           :    NFPacketSendUtil
//
// -------------------------------------------------------------------------

#pragma once

#include "NFComm/NFCore/NFPlatform.h"
#include "proto_cs_cmd.pb.h"

enum
{
	PROTOCOL_CHAR_BUFF_SIZE = 1024*1024, //1M
};

inline bool IS_CS_REQ_MSG_IN_BLACKLIST(uint16_t wCmd)
{
	switch (wCmd)
	{
		case proto_ff::E_CS_LOGIN_REQ:
		case proto_ff::E_CS_LOGOUT_REQ:
		case proto_ff::E_CS_GETROLE_REQ:
			return true;
		break;
	}

	return false;
}

inline bool IS_CS_RSP_MSG_IN_BLACKLIST(uint16_t wCmd)
{
	switch (wCmd)
	{
		case proto_ff::E_CS_HEARTBEAT_RSP:
		case proto_ff::E_CS_RELAY_RSP:
		case proto_ff::E_CS_LOGIN_RES:
		case proto_ff::E_CS_LOGOUT_RSP:
		case proto_ff::E_CS_GETROLE_RSP:
		case proto_ff::E_CS_ERROR:
		case proto_ff::E_CS_BATTLESVR_RTT_RSP:
			return true;
		break;
	}

	return false;
}

class NFSession;
class NFPlayer;
class NFPacketSendUtil
{
public:
	static int SendToClient(NFSession* pSession, uint32_t cmd, const google::protobuf::Message* pstMsgRes);
	static int SendToClient(NFSession* pSession, uint32_t cmd, const std::string& strData);
	static int SendToClient(NFPlayer* pPlayer, uint32_t cmd, const google::protobuf::Message* pstMsgRes);
	static int SendToClientDirectly(NFSession* pSession, uint32_t cmd, const google::protobuf::Message* pstMsgRes);
	static int SendToClientDirectly(int connID, int objID, int connBusID, uint32_t cmd, const google::protobuf::Message* pstMsgRes);

	static int SendToClientFinally(NFSession* pSession, void* pBuff, uint32_t ulSize);

    static int BroadcastAllLogic(uint32_t cmd, const google::protobuf::Message* pstMsgRes);
	static int Broadcast(uint32_t cmd, const google::protobuf::Message* pstMsgRes);
	static int Multicast(const std::vector<NFSession*>& vecSession, uint32_t cmd, const google::protobuf::Message* pstMsgRes);

	static int SendErrToClient(NFSession* pSession, uint32_t req_cmd, int result);
	static int SendErrToClient(NFPlayer* pPlayer, uint32_t req_cmd, int result);
	static int SendErrToClient(int connID, int objID, int connBusID, uint32_t req_cmd, proto_ff::Proto_CS_ErrorCode result);

	static int SendGMResToClient(NFSession* pSession, int iRet, const std::string& content);
};
